﻿<!--#include file="Const.asp" -->
<!--#include file="ConnSiteData.asp" -->
<!--#include file="NoSqlHack.asp" -->
<!--#include file="Template.asp" -->
<%
'获取首页模版路径
function index_temp(yy)
index_temp=opentxt(server.mappath(installdir & "template/"&indexskin&"/Index.html"),yy)
end function

'获取关于我们模版路径
function About_temp()
About_temp=opentxt(server.mappath(installdir & "template/"&indexskin&"/About.html"))
end function

'获取新闻列表模版路径
function newslist_temp()
newslist_temp=opentxt(server.mappath(installdir & "template/"&indexskin&"/News_list.html"))
end function

'获取新闻内容模版路径
function newscontent_temp()
newscontent_temp=opentxt(server.mappath(installdir & "template/"&indexskin&"/News_view.html"))
end function

'获取产品列表模版路径
function product_list_temp()
product_list_temp=opentxt(server.mappath(installdir & "template/"&indexskin&"/Product_list.html"))
end function

'获取产品内容模版路径
function product_view_temp()
product_view_temp=opentxt(server.mappath(installdir & "template/"&indexskin&"/Product_view.html"))
end function

'获取留言模版路径
function book_temp()
book_temp=opentxt(server.mappath(installdir & "template/"&indexskin&"/book.html"))
end function

'获取留言模版路径
function search_temp()
search_temp=opentxt(server.mappath(installdir & "template/"&indexskin&"/search.html"))
end function

'打开模版
Function opentxt(filePath,yy) 
set stm=Server.CreateObject("adodb.stream") 
stm.Type=1 'adTypeBinary，按二进制数据读入 
stm.Mode=3 'adModeReadWrite ,这里只能用3用其他会出错
stm.Open 
stm.LoadFromFile filePath
stm.Position=0 '把指针移回起点 
stm.Type=2 '文本数据 
stm.Charset="utf-8"
opentxt = tempclass(stm.ReadText,yy) 
stm.Close 
set stm=nothing 
End Function 

'function tempclass(mb)
'Martech=qbq(mb)
'Martech=sys(Martech)'系统
'Martech=memu(Martech)'导航
'Martech=news(Martech)'列表
'Martech=Category(Martech)'分类
'Martech=NewsContent(Martech)'内容
'Martech=newslist(Martech)
'Martech=NewsSort(Martech)
'Martech=ProductSort(Martech)
'Martech=Product(Martech)'列表
'Martech=Productlist(Martech)
'tempclass=Martech
'end function

'匹配单标签
function qbq(str)
set reg=new regexp
reg.IgnoreCase = False 
reg.Global = True 
reg.Pattern = "{qbq:([0-9]+)?}"
set aa=reg.execute(str)
for each match in aa
dbq=match.submatches(0)
ybq=match
next
qbq=str
end function

'系统标签替换
function Sys(a,yy)
  set rs = server.createobject("adodb.recordset")
  sql="select top 1 * from Martech_Site"
  rs.open sql,conn,1,1
if yy="en" then
a=replace(a,"{Sys:SiteTitle}",rs("eSiteTitle"))'网站名称
a=replace(a,"{Sys:SiteUrl}",rs("SiteUrl"))'网址
a=replace(a,"{Sys:ComName}",rs("eComName")&Y)'公司名称
a=replace(a,"{Sys:Address}",rs("eAddress"))'地址
a=replace(a,"{Sys:ZipCode}",rs("ZipCode"))'邮编
a=replace(a,"{Sys:Telephone}",rs("Telephone"))'电话
a=replace(a,"{Sys:Fax}",rs("Fax"))'传真
a=replace(a,"{Sys:Email}",rs("Email"))'电子邮件
a=replace(a,"{Sys:Keywords}",rs("eKeywords"))'网站关键字
a=replace(a,"{Sys:Descriptions}",rs("eDescriptions"))'网站介绍
a=replace(a,"{Sys:IcpNumber}",rs("IcpNumber"))'icp备案号
a=replace(a,"{Sys:indexskin}",indexskin)'皮肤路径
a=replace(a,"{Sys:QQ}",qq_service_fd())'皮肤路径
'a=replace(a,"{Sys:Power}",Power)'Power
'a=replace(a,"{Sys:Flash1}",Flash(768,210))'flash
'a=replace(a,"{Sys:Flash2}",Flash(740,170))'flash
else
a=replace(a,"{Sys:SiteTitle}",rs("SiteTitle"))'网站名称
a=replace(a,"{Sys:SiteUrl}",rs("SiteUrl"))'网址
a=replace(a,"{Sys:ComName}",rs("ComName")&Y)'公司名称
a=replace(a,"{Sys:Address}",rs("Address"))'地址
a=replace(a,"{Sys:ZipCode}",rs("ZipCode"))'邮编
a=replace(a,"{Sys:Telephone}",rs("Telephone"))'电话
a=replace(a,"{Sys:Fax}",rs("Fax"))'传真
a=replace(a,"{Sys:Email}",rs("Email"))'电子邮件
a=replace(a,"{Sys:Keywords}",rs("Keywords"))'网站关键字
a=replace(a,"{Sys:Descriptions}",rs("Descriptions"))'网站介绍
a=replace(a,"{Sys:IcpNumber}",rs("IcpNumber"))'icp备案号
a=replace(a,"{Sys:indexskin}",indexskin)'皮肤路径
a=replace(a,"{Sys:QQ}",qq_service_fd())'皮肤路径
'a=replace(a,"{Sys:Power}",Power)'Power
'a=replace(a,"{Sys:Flash1}",Flash(768,210))'flash
'a=replace(a,"{Sys:Flash2}",Flash(740,170))'flash
end if
Sys=a
  rs.close
  set rs=nothing
end Function

function Books(str)
str=replace(str,"{Book}",book())'
Books=str
end Function


'分类标签替换-----只分两级类别
function Category(cat)
cat=replace(cat,"{Category:productcat}",SortMenu("Martech_ProductSort",0,0,1,"Product_List"))'产品分类
cat=replace(cat,"{Category:newscat}",SortMenu("Martech_newsSort",0,0,1,"News_List"))'新闻分类
Category=cat
end Function

'读取分类数据
Function SortMenu(DateForm,ParentID,i,level,names)
  set rs = server.createobject("adodb.recordset")
  sql="select * from "&DateForm&" where ViewFlag and ParentID="&ParentID&" order by ID asc"
  rs.open sql,conn,1,1
  if conn.execute("select ID from "&DateForm&" Where ViewFlag and ParentID=0").eof then
    tab=tab+"<li>暂无相关分类</li>"
  end if
  do while not rs.eof
	tab=tab+"<li><b><a href="""&names&".asp?SortID="&rs("ID")&""">"&rs("SortName")&"</a></b></li>"&vbcrlf		
 set rs1 = server.createobject("adodb.recordset")
  sql1="select * from "&DateForm&" where ViewFlag and ParentID="&rs("ID")&" order by ID asc"
  rs1.open sql1,conn,1,1
  do while not rs1.eof
	 tab=tab+"<li>&nbsp;&nbsp;<a href="""&names&".asp?SortID="&rs1("ID")&""">"&rs1("SortName")&"</a></li>"&vbcrlf  
	rs1.movenext	  
  loop 
  rs1.close
  set rs1=nothing
	rs.movenext	  
  loop 
  rs.close
  set rs=nothing
   SortMenu=tab
end Function



'导航调用
function Memu(str,yy)
set reg=new regexp
reg.IgnoreCase = False 
reg.Global = True 
'reg.Pattern = "{Memu([\s\S.]*?)}([\s\S.]*?){memuend}"
'reg.Pattern = "<!--\s+BEGIN\s+memu([\s\S.]*?)\s+-->([\s\S.]*)<!--\s+END\s+\memu\s+-->"
reg.Pattern = "<!--Memu:\{(.+?)\}-->([\s\S]*?)<!--Memu-->"
set aa=reg.execute(str)
for each match in aa
bq=match.submatches(0)
nr=match.submatches(1)
Row=nbq(bq,"Row")
Data=nbq(bq,"Data")
str=replace(str,match,Getmemu(Row,nr,Data,yy))
next
Memu=str
end function

'读取导航数据
function Getmemu(Row,mneirong,Data,yy)
  set rs = server.createobject("adodb.recordset")
if yy="en" then
  sql="select top "&Row&" * from "&Data&"  where eViewFlag order by Sequence asc"
  rs.open sql,conn,1,1
do while not rs.eof
		mneirong1=replace(mneirong,"{Memu:name}",rs("ename"))
		mneirong2=replace(mneirong1,"{Memu:id}",rs("id"))
		mneirong3=replace(mneirong2,"{Memu:url}",rs("eurl"))
xx=xx+mneirong3
rs.movenext
loop
else
	sql="select top "&Row&" * from "&Data&"  where ViewFlag order by Sequence asc"
  rs.open sql,conn,1,1
do while not rs.eof
		mneirong1=replace(mneirong,"{Memu:name}",rs("name"))
		mneirong2=replace(mneirong1,"{Memu:id}",rs("id"))
		mneirong3=replace(mneirong2,"{Memu:url}",rs("url"))
xx=xx+mneirong3
rs.movenext
loop
end if
Getmemu=xx
end Function


'---------------------------------------------------------------------
'新闻
'---------------------------------------------------------------------

'新闻title调用
Function NewsSort(a)
  set rs = server.createobject("adodb.recordset")
  sortId= request.QueryString("SortID")
  if sortId="" then 
  sql="select * from Martech_NewsSort"
    elseif not IsNumeric(sortId) then
	a=a+"暂无相关信息"
	exit function
    elseif conn.execute("select * from Martech_NewsSort Where ViewFlag and  ID="&request.QueryString("SortID")).eof then
   a=a+"暂无相关信息"
	exit function 
  else
  sql="select * from Martech_NewsSort where ID="&sortId
  end if
  rs.open sql,conn,1,1
a=replace(a,"{News:SortName}",rs("SortName"))'分类名称
a=replace(a,"{News:Sortid}",rs("id"))
  rs.close
  NewsSort=a
  set rs=nothing
end Function

'匹配新闻调用
function News(str)
set reg=new regexp
reg.IgnoreCase = False 
reg.Global = True 
'reg.Pattern = "<!--News:\{(.+?)\}-->([\s\S]*?)<!--News-->"
reg.Pattern = "<!--News:\{(.+?)\}-->([\s\S]*?)<!--News-->"
'reg.Pattern = "{arclist([\s\S.]*?)}([\s\S.]*?){arcend}"
set aa=reg.execute(str)
for each match in aa
bq=match.submatches(0)
nr=match.submatches(1)
Row=nbq(bq,"Row")
Data=nbq(bq,"Data")
SortID=nbq(bq,"SortID")
SortPath=nbq(bq,"SortPath")
Tlen=nbq(bq,"Tlen")
if Tlen="" then Tlen=20 else Tlen=cint(Tlen) end if
if Row="" then Row=5 else Row=cint(Row) end if
str=replace(str,match,Getnews(Row,nr,Data,SortID,Tlen))
next
News=str
end function

'读取新闻数据
function Getnews(Row,mneirong,Data,SortID,Tlen)
  set rs = server.createobject("adodb.recordset")
  if SortID=""then
  sql="select top "&Row&" * from "&Data&" where ViewFlag=-1 order by id asc"
  else
  sql="select top "&Row&" * from "&Data&" where ViewFlag=-1 and SortID="&SortID&" order by id asc"
  end if
  'Response.Write(sql)
  rs.open sql,conn,1,1
do while not rs.eof
mneirong1=replace(mneirong,"{News:name}",StrLeft(rs("Name"),Tlen))
mneirong2=replace(mneirong1,"{News:id}",rs("id"))
mneirong3=replace(mneirong2,"{News:sortid}",rs("sortid"))
mneirong4=replace(mneirong3,"{News:SortPath}",rs("SortPath"))
if rs("Key")<>"" then
mneirong5=replace(mneirong4,"{News:Key}",rs("Key"))
else
mneirong5=replace(mneirong4,"{News:Key}","")
end if
if rs("Miaoshu")<>"" then
mneirong6=replace(mneirong5,"{News:Miaoshu}",rs("Miaoshu"))
else
mneirong6=replace(mneirong5,"{News:Miaoshu}","")
end if
if rs("pic")<>"" then
mneirong7=replace(mneirong6,"{News:pic}",rs("pic"))
else
mneirong7=replace(mneirong6,"{News:pic}","")
end if
if rs("Source")<>"" then
mneirong8=replace(mneirong7,"{News:Source}",rs("Source"))
else
mneirong8=replace(mneirong7,"{News:Source}","")
end if
if rs("Content")<>"" then
mneirong9=replace(mneirong8,"{News:Content}",rs("Content"))
else
mneirong9=replace(mneirong8,"{News:Content}","")
end if
mneirong10=replace(mneirong9,"{News:ClickNumber}",rs("ClickNumber"))
mneirong11=replace(mneirong10,"{News:AddTime}",FormatDate(rs("Addtime"),14))
xx=xx+mneirong11

rs.movenext
loop
Getnews=xx
end Function

'匹配分类新闻列表
function Newslist(str)
set reg=new regexp
reg.IgnoreCase = False 
reg.Global = True 
'reg.Pattern = "{pagelist1([\s\S.]*?)}([\s\S.]*?){page1end}"
reg.Pattern = "<!--Newslist:\{(.+?)\}-->([\s\S]*?)<!--Newslist-->"
set aa=reg.execute(str)
for each match in aa
bq=match.submatches(0)
nr=match.submatches(1)
Data=nbq(bq,"Data")
ID=nbq(bq,"ID")
SortPath=nbq(bq,"SortPath")
n=nbq(bq,"n")
m=nbq(bq,"m")
taxis=nbq(bq,"taxis")
url=nbq(bq,"url")
str=replace(str,match,Getnewslist(Data,nr,n,m,idcount,page,pagec,pages,pagenmin,pagenmax,myself,pagenc,pageprevious,pagenext,i))
str=replace(str,"{Pages}",fenye(idcount,page,pagec,pages,pagenmin,pagenmax,myself,pagenc,pageprevious,pagenext,i))
next
newslist=str
end function

function getnewslist(Data,neirong,n,m,idcount,page,pagec,pages,pagenmin,pagenmax,myself,pagenc,pageprevious,pagenext,i)
  dim rs,sql
  dim HideSort '未对外发布的类别
  set rs = server.createobject("adodb.recordset")
  '根据当前类别ID取需要列表产品的类别路径SortPath开始
  ID=request.QueryString("SortID")
  if ID="" then
	SortPath="0," 
  elseif not IsNumeric(ID) then
   xx=xx+"暂无相关信息"
	exit function
  elseif conn.execute("select * from Martech_"& Data &"Sort Where ViewFlag and  ID="&request.QueryString("SortID")).eof then
   xx=xx+"暂无相关信息"
	exit function
  else
	SortPath=conn.execute("select * from Martech_"& Data &"Sort Where ViewFlag and  ID="&request.QueryString("SortID"))("SortPath")
	conn.execute("update Martech_"& Data &"Sort set ClickNumber=ClickNumber+1 Where ID="&request.QueryString("SortID"))
  end if
  sql="select * from Martech_"& Data &"Sort Where not(ViewFlag) and Instr(SortPath,'"&SortPath&"')>0"
  '根据当前类别ID取需要列表产品的类别路径SortPath结束
  rs.open sql,conn,1,1
  while not rs.eof
	HideSort="and not(Instr(SortPath,'"&rs("SortPath")&"')>0) "&HideSort
    rs.movenext
  wend
  rs.close
  '-------------------
  'dim idCount'记录总数
  'dim pages'每页条数
      pages=n
  'dim pagec'总页数
  'dim page'页码
      page=clng(request("Page"))
 ' dim pagenc'每页显示的分页页码数量=pagenc*5+1
      pagenc=m
 ' dim pagenmax'每页显示的分页的最大页码
 ' dim pagenmin'每页显示的分页的最小页码
 ' dim pageprevious'上一相邻的页码
  'dim pagenext '下一相邻的页码
  '重置数据表名
  Datafrom="Martech_"& Data &""
  dim Datawhere'数据条件
	  Datawhere="where ViewFlag and Instr(SortPath,'"&SortPath&"')>0 "&HideSort& " "
  dim sqlid'本页需要用到的id
  'dim Myself,PATH_INFO,QUERY_STRING'本页地址和参数
      PATH_INFO = request.servervariables("PATH_INFO")
	  QUERY_STRING = request.ServerVariables("QUERY_STRING")'
      if QUERY_STRING = "" then
	    Myself = PATH_INFO & "?"
	  elseif Instr(PATH_INFO & "?" & QUERY_STRING,"Page=")=0 then
	    Myself= PATH_INFO & "?" & QUERY_STRING & "&"
	  else
	    Myself = Left(PATH_INFO & "?" & QUERY_STRING,Instr(PATH_INFO & "?" & QUERY_STRING,"Page=")-1)
	  end if
  dim taxis'排序的语句 asc,desc
      taxis="order by id desc "
 ' dim i'用于循环的整数
  '获取记录总数
  sql="select count(ID) as idCount from ["& Datafrom &"]" & Datawhere
  set rs=server.createobject("adodb.recordset")
  rs.open sql,conn,0,1
  idCount=rs("idCount")
  '获取记录总数
  if(idcount>0) then'如果记录总数=0,则不处理
    if(idcount mod pages=0)then'如果记录总数除以每页条数有余数,则=记录总数/每页条数+1
	  pagec=int(idcount/pages)'获取总页数
   	else
      pagec=int(idcount/pages)+1'获取总页数
    end if
	'获取本页需要用到的id============================================
    '读取所有记录的id数值,因为只有id所以速度很快
    sql="select id from ["& Datafrom &"] " & Datawhere & taxis
    set rs=server.createobject("adodb.recordset")
    rs.open sql,conn,1,1
    rs.pagesize = pages '每页显示记录数
    if page < 1 then page = 1
    if page > pagec then page = pagec
    if pagec > 0 then rs.absolutepage = page  
    for i=1 to rs.pagesize
	  if rs.eof then exit for  
	  if(i=1)then
	    sqlid=rs("id")
	  else
	    sqlid=sqlid &","&rs("id")
	  end if
	  rs.movenext
    next
  '获取本页需要用到的id结束============================================
  end if
  if(idcount>0 and sqlid<>"") then'如果记录总数=0,则不处理
    '用in刷选本页所语言的数据,仅读取本页所需的数据,所以速度快
    sql="select * from ["& Datafrom &"] where id in("& sqlid &") "&taxis
    set rs=server.createobject("adodb.recordset")
    rs.open sql,conn,0,1 
    while not rs.eof '填充数据到表格
	neirong1=replace(neirong,"{News:id}",rs("id"))
	neirong2=replace(neirong1,"{News:Name}",rs("Name"))
	if rs("Key")<>"" then
	neirong3=replace(neirong2,"{News:Key}",rs("Key"))
	else
	neirong3=replace(neirong2,"{News:Key}","")
	end if
	if rs("Miaoshu")<>"" then
	neirong4=replace(neirong3,"{News:Miaoshu}",rs("Miaoshu"))
	else
	neirong4=replace(neirong3,"{News:Miaoshu}","")
	end if
	if rs("pic")<>"" then
	neirong5=replace(neirong4,"{News:pic}",rs("pic"))
	else
	neirong5=replace(neirong4,"{News:pic}","")
	end if
	if rs("Source")<>"" then
	neirong6=replace(neirong5,"{News:Source}",rs("Source"))
	else
	neirong6=replace(neirong5,"{News:Source}","")
	end if
	neirong7=replace(neirong6,"{News:ClickNumber}",rs("ClickNumber"))
	neirong8=replace(neirong7,"{News:Addtime}",FormatDate(rs("Addtime"),14))
	xx=xx+neirong8
	  rs.movenext
    wend
  else
   xx=xx+"暂无相关信息"
	exit function
  end if
  rs.close
  Getnewslist=xx
  set rs=nothing
end function 

Function Newsview(a)
ID=request.QueryString("ID")
if ID="" or not IsNumeric(ID) then
a="<script language=javascript> alert('错误参数！');location.replace('News_List.asp');</script>"
  elseif conn.execute("select * from Martech_News Where ViewFlag and  ID="&ID).eof then
 a="<script language=javascript> alert('错误参数！');location.replace('News_List.asp');</script>"
 ' exit function
  else
    set rs = server.createobject("adodb.recordset")
	sql="select * from Martech_News where ViewFlag and ID="&ID
    rs.open sql,conn,1,3
	a=replace(a,"{News:Name}",rs("Name"))
	if rs("Key")<>"" then
	a=replace(a,"{News:Key}",rs("Key"))
	else
	a=replace(a,"{News:Key}","")
	end if
	if rs("Miaoshu")<>"" then
	a=replace(a,"{News:Miaoshu}",rs("Miaoshu"))
	else
	a=replace(a,"{News:Miaoshu}","")
	end if
	if rs("pic")<>"" then
	a=replace(a,"{News:pic}",rs("pic"))
	else
	a=replace(a,"{News:pic}","")
	end if
	if rs("Source")<>"" then
	a=replace(a,"{News:Source}",rs("Source"))
	else
	a=replace(a,"{News:Source}","不详")
	end if
	if rs("Content")<>"" then
	a=replace(a,"{News:Content}",rs("Content"))
	else
	a=replace(a,"{News:Content}","")
	end if
	a=replace(a,"{News:AddTime}",FormatDate(rs("Addtime"),13))
	a=replace(a,"{News:ClickNumber}","<script language=JavaScript src='inc/hits.asp?a=news&id="&rs("id")&"'></script>")
end if
 ' rs.close
  Newsview=a
  set rs=nothing
end Function


'---------------------------------------------------------------------
'产品
'---------------------------------------------------------------------
'产品title调用
Function ProductSort(a)
  set rs = server.createobject("adodb.recordset")
  sortId= request.QueryString("SortID")
  if sortId="" then 
  sql="select * from Martech_ProductSort"
    elseif not IsNumeric(sortId) then
	a=a+"暂无相关信息"
	exit function
    elseif conn.execute("select * from Martech_ProductSort Where ViewFlag and  ID="&request.QueryString("SortID")).eof then
   a=a+"暂无相关信息"
	exit function 
  else
  sql="select * from Martech_ProductSort where ID="&sortId
  end if
  rs.open sql,conn,1,1
' Response.Write(SQL)
a=replace(a,"{Product:SortName}",rs("SortName"))'分类名称
a=replace(a,"{Product:Sortid}",rs("id"))
  rs.close
  ProductSort=a
  set rs=nothing
end Function

'匹配产品调用
function Product(str)
set reg=new regexp
reg.IgnoreCase = False 
reg.Global = True 
reg.Pattern = "<!--Product:\{(.+?)\}-->([\s\S]*?)<!--Product-->"
set aa=reg.execute(str)
for each match in aa
bq=match.submatches(0)
nr=match.submatches(1)
Row=nbq(bq,"Row")
Data=nbq(bq,"Data")
SortID=nbq(bq,"SortID")
SortPath=nbq(bq,"SortPath")
Tlen=nbq(bq,"Tlen")
CommendFlag=nbq(bq,"CommendFlag")
NewFlag=nbq(bq,"NewFlag")
if Tlen="" then Tlen=20 else Tlen=cint(Tlen) end if
if Row="" then Row=5 else Row=cint(Row) end if
'if CommendFlag="" then CommendFlag=0 else CommendFlag=cint(CommendFlag) end if
'if NewFlag="" then NewFlag=-0 else NewFlag=cint(NewFlag) end if
str=replace(str,match,GetProduct(Row,nr,Data,SortID,Tlen,CommendFlag,NewFlag))
next
Product=str
end function

'读取产品数据
function GetProduct(Row,mneirong,Data,SortID,Tlen,CommendFlag,NewFlag)
  set rs = server.createobject("adodb.recordset")
'  if sortID="" then 
'   sql="select top "&Row&" * from "&Data&" where ViewFlag=-1 and CommendFlag="&CommendFlag&" and NewFlag="&NewFlag&"  order by id asc"
'   else
'  sql="select top "&Row&" * from "&Data&" where ViewFlag=-1 and SortID="&SortID&" and CommendFlag="&CommendFlag&" and NewFlag="&NewFlag&" order by id asc"
'  end if

	if sortID="" and  CommendFlag="" and NewFlag=""  then 
	 sql="select top "&Row&" * from "&Data&" where ViewFlag=-1  order by id desc"
	elseif sortID<>"" and  CommendFlag="" and NewFlag="" then
	 sql="select top "&Row&" * from "&Data&" where ViewFlag=-1 and SortID="&SortID&" order by id desc"
	elseif sortID<>"" and  CommendFlag<>"" and NewFlag="" then
	 sql="select top "&Row&" * from "&Data&" where ViewFlag=-1 and SortID="&SortID&" and CommendFlag="&CommendFlag&" order by id desc"
	elseif sortID<>"" and  CommendFlag<>"" and NewFlag<>"" then
	 sql="select top "&Row&" * from "&Data&" where ViewFlag=-1 and SortID="&SortID&" and CommendFlag="&CommendFlag&" and NewFlag="&NewFlag&" order by id desc"
	elseif sortID="" and  CommendFlag<>"" and NewFlag="" then
	 sql="select top "&Row&" * from "&Data&" where ViewFlag=-1  and CommendFlag="&CommendFlag&"  order by id desc"
	elseif sortID="" and  CommendFlag<>"" and NewFlag<>"" then
	 sql="select top "&Row&" * from "&Data&" where ViewFlag=-1 and CommendFlag="&CommendFlag&" and NewFlag="&NewFlag&" order by id desc"
	elseif sortID="" and  CommendFlag="" and NewFlag<>"" then
	 sql="select top "&Row&" * from "&Data&" where ViewFlag=-1 and NewFlag="&NewFlag&" order by id desc"
	elseif sortID<>"" and  CommendFlag="" and NewFlag<>"" then
	 sql="select top "&Row&" * from "&Data&" where ViewFlag=-1 and SortID="&SortID&" and NewFlag="&NewFlag&" order by id desc"
	end if
  'Response.Write(sql)
  rs.open sql,conn,1,1
do while not rs.eof
mneirong1=replace(mneirong,"{Product:name}",StrLeft(rs("Name"),Tlen))
mneirong2=replace(mneirong1,"{Product:id}",rs("id"))
mneirong3=replace(mneirong2,"{Product:sortid}",rs("sortid"))
mneirong4=replace(mneirong3,"{Product:SortPath}",rs("SortPath"))
if rs("Key")<>"" then
mneirong5=replace(mneirong4,"{Product:Key}",rs("Key"))
else
mneirong5=replace(mneirong4,"{Product:Key}","")
end if
if rs("Miaoshu")<>"" then
mneirong6=replace(mneirong5,"{Product:Miaoshu}",rs("Miaoshu"))
else
mneirong6=replace(mneirong5,"{Product:Miaoshu}","")
end if
if rs("ProductModel")<>"" then
mneirong7=replace(mneirong6,"{Product:ProductModel}",rs("ProductModel"))
else
mneirong7=replace(mneirong6,"{Product:ProductModel}","")
end if
if rs("Unit")<>"" then
mneirong8=replace(mneirong7,"{Product:Unit}",rs("Unit"))
else
mneirong8=replace(mneirong7,"{Product:Unit}","")
end if
if rs("Maker")<>"" then
mneirong9=replace(mneirong8,"{Product:Maker}",rs("Maker"))
else
mneirong9=replace(mneirong8,"{Product:Maker}","")
end if
mneirong10=replace(mneirong9,"{Product:ClickNumber}",rs("ClickNumber"))
mneirong11=replace(mneirong10,"{Product:AddTime}",FormatDate(rs("Addtime"),13))
mneirong12=replace(mneirong11,"{Product:ProductNo}",rs("ProductNo"))
mneirong13=replace(mneirong12,"{Product:N_Price}",rs("N_Price"))
mneirong14=replace(mneirong13,"{Product:P_Price}",rs("P_Price"))
mneirong15=replace(mneirong14,"{Product:Stock}",rs("Stock"))
if rs("SmallPic")<>"" then
mneirong16=replace(mneirong15,"{Product:SmallPic}",rs("SmallPic"))
else
mneirong16=replace(mneirong15,"{Product:SmallPic}","")
end if
if rs("BigPic")<>"" then
mneirong17=replace(mneirong16,"{Product:BigPic}",rs("BigPic"))
else
mneirong17=replace(mneirong16,"{Product:BigPic}","")
end if
if rs("Content")<>"" then
mneirong18=replace(mneirong17,"{Product:Content}",rs("Content"))
else
mneirong18=replace(mneirong17,"{Product:Content}","")
end if
mneirong19=replace(mneirong18,"{Product:UpdateTime}",rs("UpdateTime"))
xx=xx+mneirong19
rs.movenext
loop
GetProduct=xx
end Function

'匹配分类产品列表
function Productlist(str)
set reg=new regexp
reg.IgnoreCase = False 
reg.Global = True 
reg.Pattern = "<!--Productlist:\{(.+?)\}-->([\s\S]*?)<!--Productlist-->"
set aa=reg.execute(str)
for each match in aa
bq=match.submatches(0)
nr=match.submatches(1)
Data=nbq(bq,"Data")
ID=nbq(bq,"ID")
SortPath=nbq(bq,"SortPath")
n=nbq(bq,"n")
m=nbq(bq,"m")
taxis=nbq(bq,"taxis")
url=nbq(bq,"url")
str=replace(str,match,GetProductlist(Data,nr,n,m,idcount,page,pagec,pages,pagenmin,pagenmax,myself,pagenc,pageprevious,pagenext,i))
str=replace(str,"{Pages}",fenye(idcount,page,pagec,pages,pagenmin,pagenmax,myself,pagenc,pageprevious,pagenext,i))
next
Productlist=str
end function

function GetProductlist(Data,neirong,n,m,idcount,page,pagec,pages,pagenmin,pagenmax,myself,pagenc,pageprevious,pagenext,i)
  dim rs,sql
  dim HideSort '未对外发布的类别
  set rs = server.createobject("adodb.recordset")
  '根据当前类别ID取需要列表产品的类别路径SortPath开始
  ID=request.QueryString("SortID")
  if ID="" then
	SortPath="0," 
  elseif not IsNumeric(ID) then
   xx=xx+"暂无相关信息"
	exit function
  elseif conn.execute("select * from Martech_"& Data &"Sort Where ViewFlag and  ID="&request.QueryString("SortID")).eof then
   xx=xx+"暂无相关信息"
	exit function
  else
	SortPath=conn.execute("select * from Martech_"& Data &"Sort Where ViewFlag and  ID="&request.QueryString("SortID"))("SortPath")
	conn.execute("update Martech_"& Data &"Sort set ClickNumber=ClickNumber+1 Where ID="&request.QueryString("SortID"))
  end if
  sql="select * from Martech_"& Data &"Sort Where not(ViewFlag) and Instr(SortPath,'"&SortPath&"')>0"
  '根据当前类别ID取需要列表产品的类别路径SortPath结束
  rs.open sql,conn,1,1
  while not rs.eof
	HideSort="and not(Instr(SortPath,'"&rs("SortPath")&"')>0) "&HideSort
    rs.movenext
  wend
  rs.close
  '-------------------
  'dim idCount'记录总数
  'dim pages'每页条数
      pages=n
  'dim pagec'总页数
  'dim page'页码
      page=clng(request("Page"))
 ' dim pagenc'每页显示的分页页码数量=pagenc*5+1
      pagenc=m
 ' dim pagenmax'每页显示的分页的最大页码
 ' dim pagenmin'每页显示的分页的最小页码
 ' dim pageprevious'上一相邻的页码
  'dim pagenext '下一相邻的页码
  '重置数据表名
  Datafrom="Martech_"& Data &""
  dim Datawhere'数据条件
	  Datawhere="where ViewFlag and Instr(SortPath,'"&SortPath&"')>0 "&HideSort& " "
  dim sqlid'本页需要用到的id
  'dim Myself,PATH_INFO,QUERY_STRING'本页地址和参数
      PATH_INFO = request.servervariables("PATH_INFO")
	  QUERY_STRING = request.ServerVariables("QUERY_STRING")'
      if QUERY_STRING = "" then
	    Myself = PATH_INFO & "?"
	  elseif Instr(PATH_INFO & "?" & QUERY_STRING,"Page=")=0 then
	    Myself= PATH_INFO & "?" & QUERY_STRING & "&"
	  else
	    Myself = Left(PATH_INFO & "?" & QUERY_STRING,Instr(PATH_INFO & "?" & QUERY_STRING,"Page=")-1)
	  end if
  dim taxis'排序的语句 asc,desc
      taxis="order by id desc "
 ' dim i'用于循环的整数
  '获取记录总数
  sql="select count(ID) as idCount from ["& Datafrom &"]" & Datawhere
  set rs=server.createobject("adodb.recordset")
  rs.open sql,conn,0,1
  idCount=rs("idCount")
  '获取记录总数
  if(idcount>0) then'如果记录总数=0,则不处理
    if(idcount mod pages=0)then'如果记录总数除以每页条数有余数,则=记录总数/每页条数+1
	  pagec=int(idcount/pages)'获取总页数
   	else
      pagec=int(idcount/pages)+1'获取总页数
    end if
	'获取本页需要用到的id============================================
    '读取所有记录的id数值,因为只有id所以速度很快
    sql="select id from ["& Datafrom &"] " & Datawhere & taxis
    set rs=server.createobject("adodb.recordset")
    rs.open sql,conn,1,1
    rs.pagesize = pages '每页显示记录数
    if page < 1 then page = 1
    if page > pagec then page = pagec
    if pagec > 0 then rs.absolutepage = page  
    for i=1 to rs.pagesize
	  if rs.eof then exit for  
	  if(i=1)then
	    sqlid=rs("id")
	  else
	    sqlid=sqlid &","&rs("id")
	  end if
	  rs.movenext
    next
  '获取本页需要用到的id结束============================================
  end if
  if(idcount>0 and sqlid<>"") then'如果记录总数=0,则不处理
    '用in刷选本页所语言的数据,仅读取本页所需的数据,所以速度快
    sql="select * from ["& Datafrom &"] where id in("& sqlid &") "&taxis
    set rs=server.createobject("adodb.recordset")
    rs.open sql,conn,0,1 
    while not rs.eof '填充数据到表格
neirong1=replace(neirong,"{Product:name}",rs("Name"))
neirong2=replace(neirong1,"{Product:id}",rs("id"))
neirong3=replace(neirong2,"{Product:sortid}",rs("sortid"))
neirong4=replace(neirong3,"{Product:SortPath}",rs("SortPath"))
if rs("Key")<>"" then
neirong5=replace(neirong4,"{Product:Key}",rs("Key"))
else
neirong5=replace(neirong4,"{Product:Key}","")
end if
if rs("Miaoshu")<>"" then
neirong6=replace(neirong5,"{Product:Miaoshu}",rs("Miaoshu"))
else
neirong6=replace(neirong5,"{Product:Miaoshu}","")
end if
if rs("ProductModel")<>"" then
neirong7=replace(neirong6,"{Product:ProductModel}",rs("ProductModel"))
else
neirong7=replace(neirong6,"{Product:ProductModel}","")
end if
if rs("Unit")<>"" then
neirong8=replace(neirong7,"{Product:Unit}",rs("Unit"))
else
neirong8=replace(neirong7,"{Product:Unit}","")
end if
if rs("Maker")<>"" then
neirong9=replace(neirong8,"{Product:Maker}",rs("Maker"))
else
neirong9=replace(neirong8,"{Product:Maker}","")
end if
neirong10=replace(neirong9,"{Product:ClickNumber}",rs("ClickNumber"))
neirong11=replace(neirong10,"{Product:AddTime}",FormatDate(rs("Addtime"),13))
neirong12=replace(neirong11,"{Product:ProductNo}",rs("ProductNo"))
neirong13=replace(neirong12,"{Product:N_Price}",rs("N_Price"))
neirong14=replace(neirong13,"{Product:P_Price}",rs("P_Price"))
neirong15=replace(neirong14,"{Product:Stock}",rs("Stock"))
if rs("SmallPic")<>"" then
neirong16=replace(neirong15,"{Product:SmallPic}",rs("SmallPic"))
else
neirong16=replace(neirong15,"{Product:SmallPic}","")
end if
if rs("BigPic")<>"" then
neirong17=replace(neirong16,"{Product:BigPic}",rs("BigPic"))
else
neirong17=replace(neirong16,"{Product:BigPic}","")
end if
if rs("Content")<>"" then
neirong18=replace(neirong17,"{Product:Content}",rs("Content"))
else
neirong18=replace(neirong17,"{Product:Content}","")
end if
neirong19=replace(neirong18,"{Product:UpdateTime}",rs("UpdateTime"))
xx=xx+neirong19
	  rs.movenext
    wend
  else
   xx=xx+"暂无相关信息"
	exit function
  end if
  rs.close
  GetProductlist=xx
  set rs=nothing
end function 

Function Product_view(a)
ID=request.QueryString("ID")
if ID="" or not IsNumeric(ID) then
'xx=xx+"暂无相关信息"
 a="<script language=javascript> alert('错误参数！');location.replace('Product_List.asp');</script>"
  elseif conn.execute("select * from Martech_Product Where ViewFlag and  ID="&ID).eof then
  'xx=xx+"暂无相关信息"
   a="<script language=javascript> alert('错误参数！');location.replace('Product_List.asp');</script>"
 ' exit function
  else
    set rs = server.createobject("adodb.recordset")
	sql="select * from Martech_Product where ViewFlag and ID="&ID
    rs.open sql,conn,1,3
	a=replace(a,"{Product:Name}",rs("Name"))
	if rs("Key")<>"" then
	a=replace(a,"{Product:Key}",rs("Key"))
	else
	a=replace(a,"{Product:Key}","")
	end if
	if rs("Miaoshu")<>"" then
	a=replace(a,"{Product:Miaoshu}",rs("Miaoshu"))
	else
	a=replace(a,"{Product:Miaoshu}","")
	end if
	a=replace(a,"{Product:N_Price}",rs("N_Price"))
	a=replace(a,"{Product:P_Price}",rs("P_Price"))
	a=replace(a,"{Product:ProductNo}",rs("ProductNo"))
	a=replace(a,"{Product:ProductModel}",rs("ProductModel"))
	a=replace(a,"{Product:Stock}",rs("Stock"))
	if rs("Unit")<>"" then
	a=replace(a,"{Product:Unit}",rs("Unit"))
	else
	a=replace(a,"{Product:Unit}","")
	end if
	if rs("Maker")<>"" then
	a=replace(a,"{Product:Maker}",rs("Maker"))
	else
	a=replace(a,"{Product:Maker}","")
	end if
	if rs("SmallPic")<>"" then
	a=replace(a,"{Product:SmallPic}",rs("SmallPic"))
	else
	a=replace(a,"{Product:SmallPic}","")
	end if
	if rs("BigPic")<>"" then
	a=replace(a,"{Product:BigPic}",rs("BigPic"))
	else
	a=replace(a,"{Product:BigPic}","")
	end if
	if rs("Content")<>"" then
	a=replace(a,"{Product:Content}",rs("Content"))
	else
	a=replace(a,"{Product:Content}","")
	end if
	a=replace(a,"{Product:AddTime}",FormatDate(rs("Addtime"),13))
	a=replace(a,"{Product:UpdateTime}",FormatDate(rs("UpdateTime"),13))
	a=replace(a,"{Product:ClickNumber}","<script language=JavaScript src='inc/hits.asp?a=Product&id="&rs("id")&"'></script>")
end if
 ' rs.close
  Product_view=a
  set rs=nothing
end Function

'关于我们
function About(a)
ID=request.QueryString("ID")
  set rs = server.createobject("adodb.recordset")
  if ID="" or not IsNumeric(ID) then
	sql="select top 1 * from Martech_About where ViewFlag  order by Sequence asc"
  else
	sql="select * from Martech_About where ViewFlag and ID="&ID
  end if
  rs.open sql,conn,1,3
  if rs.eof then
    a="<script language=javascript> alert('错误参数！');location.replace('About.asp');</script>"
  else
  a=replace(a,"{About:Name}",rs("Name"))
	if rs("Key")<>"" then
	a=replace(a,"{About:Key}",rs("Key"))
	else
	a=replace(a,"{About:Key}","")
	end if
	if rs("Miaoshu")<>"" then
	a=replace(a,"{About:Miaoshu}",rs("Miaoshu"))
	else
	a=replace(a,"{About:Miaoshu}","")
	end if
	a=replace(a,"{About:AddTime}",FormatDate(rs("UpdateTime"),13))
	if rs("Content")<>"" then
	a=replace(a,"{About:Content}",rs("Content"))
	else
	a=replace(a,"{About:Content}","")
	end if
	a=replace(a,"{About:ClickNumber}","<script language=JavaScript src='inc/hits.asp?a=About&id="&rs("id")&"'></script>")
  end if
  rs.close
  About=a
  set rs=nothing
end function

'导航调用
function Aboutlist(str)
set reg=new regexp
reg.IgnoreCase = False 
reg.Global = True 
reg.Pattern = "<!--Aboutlist:\{(.+?)\}-->([\s\S]*?)<!--Aboutlist-->"
set aa=reg.execute(str)
for each match in aa
bq=match.submatches(0)
nr=match.submatches(1)
Row=nbq(bq,"Row")
Data=nbq(bq,"Data")
if Row="" then Row=20 else Row=cint(Row) end if
str=replace(str,match,GetAboutlist(nr,Data))
next
Aboutlist=str
end function

'读取导航数据
function GetAboutlist(neirong,Data)
  set rs = server.createobject("adodb.recordset")
  sql="select  * from "&Data&"  where ViewFlag order by Sequence asc"
  rs.open sql,conn,1,1
do while not rs.eof
neirong1=replace(neirong,"{About:name}",rs("Name"))
neirong2=replace(neirong1,"{About:id}",rs("id"))
if rs("Key")<>"" then
neirong3=replace(neirong2,"{About:Key}",rs("Key"))
else
neirong3=replace(neirong2,"{About:Key}","")
end if
if rs("Miaoshu")<>"" then
neirong4=replace(neirong3,"{About:Miaoshu}",rs("Miaoshu"))
else
neirong4=replace(neirong3,"{About:Miaoshu}","")
end if
if rs("Content")<>"" then
neirong5=replace(neirong4,"{About:Content}",rs("Content"))
else
neirong5=replace(neirong4,"{About:Content}","")
end if
xx=xx+neirong5
rs.movenext
loop
GetAboutlist=xx
end Function



'bq内循环匹配
function nbq(xx,yy)
set reg=new regexp
reg.IgnoreCase = False 
reg.Global = True 
reg.pattern=""&yy&"=([a-zA-Z0-9_]+)"
set matches=reg.execute(xx)
for each match in matches
aa=match.submatches(0)
next
nbq=aa
end Function

'替换分类单标签
function pth(p)
if classid="" then
pth=p
else
set ct=new category
ct.getcategoryinfo(classid)
p=replace(p,"{qesy:cname}",ct.rs("cname"))
pth=p
end if
end function

	
'系统标签替换
function book()
id=Request.QueryString("id")
if id="" or not isnumeric(id) then url_return "参数错误!"
sql="select k,name from Martech_form where id="&id
Set rs=conn.execute(sql)
if rs.eof then  url_return "找不到指定的DIY表单!"
if rs(0)<>1 then url_return "暂时不能填写指定的表单数据!"
frmname=rs(1)
rs.Close
Set rs=nothing
'------------------------------------------------------------------------------------------
sql="select * from Martech_form_q where fid="&id&" order by id asc"
Set rs=Server.CreateObject("adodb.recordset")
rs.Open sql,conn,1,1
if rs.eof then url_return "改表单没有数据!"
ti=0
frmData="<form id=""form1"" name=""form1"" method=""post"" action=""?action=Save&id="&id&""">"
do while not rs.eof
	ti=ti+1
	v="a_"&rs("id")
	if rs("y")=1 then y="<font color=""red"">*&nbsp;&nbsp;为必填内容</font>" else y=""
	frmData=frmData&"<label for="""&v&""">"&rs("q")&"：</label>"&vbcrlf
	select case cstr(rs("t"))
		case 1
		ar=Split(rs("a"),"|")
		for i=LBOUND(ar) to UBOUND(ar)
		frmData=frmData&"<input type=""radio"" name="""&v&""" value='"&ar(i)&"' />"&ar(i)&""
		next
		frmData=frmData&"&nbsp;"&y&"<br />"&vbcrlf
		case 2
		ar=Split(rs("a"),"|")
		for i=LBOUND(ar) to UBOUND(ar)
		frmData=frmData&"<input type=""checkbox"" name="""&v&""" value="""&ar(i)&""" />"&ar(i)&""
		next
		frmData=frmData&"&nbsp;"&y&"<br />"&vbcrlf
		case 3
		frmData=frmData&"<select name="""&v&""">"
		ar=Split(rs("a"),"|")
		for i=LBOUND(ar) to UBOUND(ar)
		frmData=frmData&"<option value="""&i&""">"&ar(i)&"</option>"
		next
		frmData=frmData&"</select>"
		frmData=frmData&"&nbsp;"&y&"<br />"&vbcrlf
		case 4
		frmData=frmData&"<input name="""&v&""" type=""text"" value="""" />"
		frmData=frmData&"&nbsp;"&y&"<br />"&vbcrlf
		case 5
		frmData=frmData&"<textarea name="""&v&""" cols=""45"" Rows=""5""></textarea>"
		frmData=frmData&"&nbsp;"&y&"<br />"&vbcrlf
		case else url_return "表单存在关键错误!"
	end select	
	'frmData=frmData&"&nbsp;"&y&""&vbcrlf
	rs.MoveNext
loop
    frmData=frmData&"<input name=""fid"" type=""hidden"" value="""&id&""" />"&vbcrlf
    frmData=frmData&"<div align=""center""><input type=""submit"" name=""Submit"" value="" 提 交 "" /></div>"&vbcrlf
	frmData=frmData&"</form>"&vbcrlf
	book=frmData
	end function

'================================================
'函数名：fenye
'作　用：调用分页
'参　数：idcount,page,pagec,pages,pagenmin,pagenmax,myself,pagenc,pageprevious,pagenext,i
'返回值：
'适用范围：新闻，产品，下载，其它信息等分页用
'================================================
function fenye(idcount,page,pagec,pages,pagenmin,pagenmax,myself,pagenc,pageprevious,pagenext,i)
  xx=xx+ "<div class=""viciao"">" & vbCrLf
  xx=xx+ "|&nbsp;共计：<font color=""#ff6600"">"&idcount&"</font>条记录&nbsp;&nbsp;页次：<font color=""#ff6600"">"&page&"</font></strong>/"&pagec&"&nbsp;&nbsp;每页：<font color=""#ff6600"">"&pages&"</font>条&nbsp;&nbsp;&nbsp;&nbsp;" & vbCrLf
  pagenmin=page-pagenc '计算页码开始值
  pagenmax=page+pagenc '计算页码结束值
  if(pagenmin<1) then pagenmin=1 '如果页码开始值小于1则=1
  if(page>1) then xx=xx+"<a href="""& myself &"Page=1"" title=""跳到第1页""><img src=""../Images/ArRow_08_first.gif"" width=""9"" height=""8"" /></a>&nbsp;&nbsp;" '如果页码大于1则显示(第一页)
  if page-(pagenc*2+1)<=0 then
	pageprevious=1
  else
	pageprevious=page-(pagenc*2+1)
  end if
  if(pagenmin>1) then xx=xx+"<a href="""& myself &"Page="& pageprevious &""" title=""第"& pageprevious &"页""><img src=""../Images/ArRow_08_Previous.gif"" width=""8"" height=""8"" /></a>&nbsp;&nbsp;" '如果页码开始值大于1则显示(更前)
  if(pagenmax>pagec) then pagenmax=pagec '如果页码结束值大于总页数,则=总页数
  for i = pagenmin to pagenmax'循环输出页码
	if(i=page) then
	  xx=xx+"<span class=""current"">"& i &"</span>"
	else
	  xx=xx+"<a href="""& myself &"Page="& i &""">"& i &"</a>"
	end if
  next
  if page+(pagenc*2+1)>=pagec then
    pagenext=pagec
  else
    pagenext=page+(pagenc*2+1)
  end if
  if(pagenmax<pagec) then xx=xx+"&nbsp;&nbsp;<a href="""& myself &"Page="& pagenext &""" title=""跳到第"&pagenext&"页""><img src=""../Images/ArRow_08_next.gif"" width=""8"" height=""8"" /></a>&nbsp;" '如果页码结束值小于总页数则显示(更后)
  if(page<pagec) then xx=xx+"&nbsp;<a href="""& myself &"Page="& pagec &""" title=""跳到第"&pagec&"页""><img src=""../Images/ArRow_08_last.gif"" width=""9"" height=""8"" /></a>" '如果页码小于总页数则显示(最后页)	
  xx=xx+ "</div>" & vbCrLf
  fenye=xx
  end function	
  
'友情连接调用
function FriendLink(str)
set reg=new regexp
reg.IgnoreCase = False 
reg.Global = True 
reg.Pattern = "<!--FriendLink:\{(.+?)\}-->([\s\S]*?)<!--FriendLink-->"
set aa=reg.execute(str)
for each match in aa
bq=match.submatches(0)
nr=match.submatches(1)
Row=nbq(bq,"Row")
Data=nbq(bq,"Data")
LinkType=nbq(bq,"LinkType")
if Row="" then Row=10 else Row=cint(Row) end if
if LinkType="" then LinkType=0 else LinkType=cint(LinkType) end if
str=replace(str,match,GetFriendLink(Row,nr,Data,LinkType))
next
FriendLink=str
end function

'读取友情连接数据
function GetFriendLink(Row,mneirong,Data,LinkType)
  set rs = server.createobject("adodb.recordset")
  sql="select top "&Row&" * from "&Data&"  where ViewFlag and LinkType="&LinkType&" order by Sequence desc"
  rs.open sql,conn,1,1
do while not rs.eof
mneirong1=replace(mneirong,"{FriendLink:name}",rs("name"))
mneirong2=replace(mneirong1,"{FriendLink:id}",rs("id"))
mneirong3=replace(mneirong2,"{FriendLink:url}",rs("url"))
mneirong4=replace(mneirong3,"{FriendLink:Face}",rs("Face"))
mneirong5=replace(mneirong4,"{FriendLink:Remark}",rs("Remark"))
xx=xx+mneirong5
rs.movenext
loop
GetFriendLink=xx
end Function

'匹配搜索产品列表
function Searchlist(str)
set reg=new regexp
reg.IgnoreCase = False 
reg.Global = True 
reg.Pattern = "<!--Searchlist:\{(.+?)\}-->([\s\S]*?)<!--Searchlist-->"
set aa=reg.execute(str)
for each match in aa
bq=match.submatches(0)
nr=match.submatches(1)
Data=nbq(bq,"Data")
ID=nbq(bq,"ID")
SortPath=nbq(bq,"SortPath")
n=nbq(bq,"n")
m=nbq(bq,"m")
taxis=nbq(bq,"taxis")
url=nbq(bq,"url")
str=replace(str,match,GetSearchlist(nr,n,m,idcount,page,pagec,pages,pagenmin,pagenmax,myself,pagenc,pageprevious,pagenext,i))
str=replace(str,"{Pages}",fenye(idcount,page,pagec,pages,pagenmin,pagenmax,myself,pagenc,pageprevious,pagenext,i))
next
Searchlist=str
end function

function GetSearchlist(neirong,n,m,idcount,page,pagec,pages,pagenmin,pagenmax,myself,pagenc,pageprevious,pagenext,i)

  '-------------------
  'dim idCount'记录总数
  'dim pages'每页条数
      pages=n
  'dim pagec'总页数
  'dim page'页码
      page=clng(request("Page"))
 ' dim pagenc'每页显示的分页页码数量=pagenc*5+1
      pagenc=m
 ' dim pagenmax'每页显示的分页的最大页码
 ' dim pagenmin'每页显示的分页的最小页码
 ' dim pageprevious'上一相邻的页码
  'dim pagenext '下一相邻的页码
  '重置数据表名
  dim Datafrom'数据表名
  dim Datawhere'数据条件
  	  select case Range
	  case "title"
        Datafrom="Martech_Product"
        Datawhere="where ViewFlag and Name like '%"&KeyWord&"%'"
	  case "ProductNo"
        Datafrom="Martech_Product"
        Datawhere="where ViewFlag and ProductNo like '%"&KeyWord&"%'"
	  case "Content"
        Datafrom="Martech_Product"
        Datawhere="where ViewFlag and Content like '%"&KeyWord&"%'"
      end select  
  
  dim sqlid'本页需要用到的id
  'dim Myself,PATH_INFO,QUERY_STRING'本页地址和参数
      PATH_INFO = request.servervariables("PATH_INFO")
	  QUERY_STRING = request.ServerVariables("QUERY_STRING")'
      if QUERY_STRING = "" then
	    Myself = PATH_INFO & "?"
	  elseif Instr(PATH_INFO & "?" & QUERY_STRING,"Page=")=0 then
	    Myself= PATH_INFO & "?" & QUERY_STRING & "&"
	  else
	    Myself = Left(PATH_INFO & "?" & QUERY_STRING,Instr(PATH_INFO & "?" & QUERY_STRING,"Page=")-1)
	  end if
  dim taxis'排序的语句 asc,desc
      taxis="order by id desc "
 ' dim i'用于循环的整数
  '获取记录总数
  sql="select count(ID) as idCount from [Martech_Product]" & Datawhere
  set rs=server.createobject("adodb.recordset")
  rs.open sql,conn,0,1
  idCount=rs("idCount")
  '获取记录总数
  if(idcount>0) then'如果记录总数=0,则不处理
    if(idcount mod pages=0)then'如果记录总数除以每页条数有余数,则=记录总数/每页条数+1
	  pagec=int(idcount/pages)'获取总页数
   	else
      pagec=int(idcount/pages)+1'获取总页数
    end if
	'获取本页需要用到的id============================================
    '读取所有记录的id数值,因为只有id所以速度很快
    sql="select id from [Martech_Product] " & Datawhere & taxis
    set rs=server.createobject("adodb.recordset")
    rs.open sql,conn,1,1
	'Response.Write(sql)
    rs.pagesize = pages '每页显示记录数
    if page < 1 then page = 1
    if page > pagec then page = pagec
    if pagec > 0 then rs.absolutepage = page  
    for i=1 to rs.pagesize
	  if rs.eof then exit for  
	  if(i=1)then
	    sqlid=rs("id")
	  else
	    sqlid=sqlid &","&rs("id")
	  end if
	  rs.movenext
    next
  '获取本页需要用到的id结束============================================
  end if
  if(idcount>0 and sqlid<>"") then'如果记录总数=0,则不处理
    '用in刷选本页所语言的数据,仅读取本页所需的数据,所以速度快
    sql="select * from [Martech_Product] where id in("& sqlid &") "&taxis
    set rs=server.createobject("adodb.recordset")
    rs.open sql,conn,0,1 
    while not rs.eof '填充数据到表格
neirong1=replace(neirong,"{Product:name}",rs("Name"))
neirong2=replace(neirong1,"{Product:id}",rs("id"))
neirong3=replace(neirong2,"{Product:sortid}",rs("sortid"))
neirong4=replace(neirong3,"{Product:SortPath}",rs("SortPath"))
if rs("Key")<>"" then
neirong5=replace(neirong4,"{Product:Key}",rs("Key"))
else
neirong5=replace(neirong4,"{Product:Key}","")
end if
if rs("Miaoshu")<>"" then
neirong6=replace(neirong5,"{Product:Miaoshu}",rs("Miaoshu"))
else
neirong6=replace(neirong5,"{Product:Miaoshu}","")
end if
if rs("ProductModel")<>"" then
neirong7=replace(neirong6,"{Product:ProductModel}",rs("ProductModel"))
else
neirong7=replace(neirong6,"{Product:ProductModel}","")
end if
if rs("Unit")<>"" then
neirong8=replace(neirong7,"{Product:Unit}",rs("Unit"))
else
neirong8=replace(neirong7,"{Product:Unit}","")
end if
if rs("Maker")<>"" then
neirong9=replace(neirong8,"{Product:Maker}",rs("Maker"))
else
neirong9=replace(neirong8,"{Product:Maker}","")
end if
neirong10=replace(neirong9,"{Product:ClickNumber}",rs("ClickNumber"))
neirong11=replace(neirong10,"{Product:AddTime}",FormatDate(rs("Addtime"),13))
neirong12=replace(neirong11,"{Product:ProductNo}",rs("ProductNo"))
neirong13=replace(neirong12,"{Product:N_Price}",rs("N_Price"))
neirong14=replace(neirong13,"{Product:P_Price}",rs("P_Price"))
neirong15=replace(neirong14,"{Product:Stock}",rs("Stock"))
if rs("SmallPic")<>"" then
neirong16=replace(neirong15,"{Product:SmallPic}",rs("SmallPic"))
else
neirong16=replace(neirong15,"{Product:SmallPic}","")
end if
if rs("BigPic")<>"" then
neirong17=replace(neirong16,"{Product:BigPic}",rs("BigPic"))
else
neirong17=replace(neirong16,"{Product:BigPic}","")
end if
if rs("Content")<>"" then
neirong18=replace(neirong17,"{Product:Content}",rs("Content"))
else
neirong18=replace(neirong17,"{Product:Content}","")
end if
neirong19=replace(neirong18,"{Product:UpdateTime}",rs("UpdateTime"))
xx=xx+neirong19
	  rs.movenext
    wend
  else
   xx=xx+"暂无相关信息"
	exit function
  end if
  rs.close
  GetSearchlist=xx
  set rs=nothing
end function 


'首页公司介绍调用
function IndexAbout(str)
set reg=new regexp
reg.IgnoreCase = False 
reg.Global = True 
reg.Pattern = "{IndexAbout:\{(.+?)\}}"
set aa=reg.execute(str)
FOR each match in aa
bq=match.submatches(0)
'nr=match.submatches(1)
ID=nbq(bq,"ID")
X=nbq(bq,"X")
str=replace(str,match,GetIndexAbout(ID,X))
NEXT
IndexAbout=str
end function

'读取首页公司介绍
function GetIndexAbout(ID,X)
  set rs = server.createobject("adodb.recordset")
  sql="select Content from Martech_About where ViewFlag and ID="&id
  rs.open sql,conn,1,1
if rs.eof then
'mneirong1=replace(mneirong,"{IndexAbout:Content}","错误参数！")
Content="错误参数！"
else
'mneirong1=replace(mneirong,"{IndexAbout:Content}",left(rs("Content"),X))
Content=left(rs("Content"),X)
end if
xx=xx+Content
GetIndexAbout=xx
 rs.close
 set rs=nothing
end function

function Flash(str)
set reg=new regexp
reg.IgnoreCase = False 
reg.Global = True 
reg.Pattern = "{Flash:\{(.+?)\}}"
set aa=reg.execute(str)
FOR each match in aa
bq=match.submatches(0)
'nr=match.submatches(1)
X=nbq(bq,"X")
Y=nbq(bq,"Y")
str=replace(str,match,GetFlash(X,Y))
NEXT
Flash=str
end function

Function GetFlash(X,Y)
'dim flashswf,tab
  set rs = server.createobject("adodb.recordset")
  sql="select top 5 * from Martech_Flash where ViewFlag  order by Sequence asc"
  rs.open sql,conn,1,1
  if rs.bof and rs.eof then
    response.write "暂无链接"
  else
	do
flashswf =flashswf& "files+='|"&rs("pic")&"';links+='|"&rs("url")&"'"&vbcrlf
	 rs.movenext
	loop until rs.eof
  end if
  rs.close
  set rs=nothing
tab=tab+"<SCRIPT type=text/javascript> "&vbLf
tab=tab+"var swf_width="&x&"; "&vbLf
tab=tab+"var swf_height="&y&"; "&vbLf
tab=tab+"var config='5|0xffffff|0x666666|80|0xffffff|0x666666|0x000000';"&vbLf
tab=tab+"var files='',links='', texts=''; "&vbLf
tab=tab+""&flashswf&"; "&vbLf
tab=tab+"files=files.substring(1);links=links.substring(1);texts=texts.substring(1); "&vbLf
tab=tab+"document.write('<object classid=""clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"" codebase=""http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"" width=""'+ swf_width +'"" height=""'+ swf_height +'"">'); "&vbLf
tab=tab+"document.write('<param name=""movie"" value=""images/focus.swf"" />'); "&vbLf
tab=tab+"document.write('<param name=""quality"" value=""high"" />'); "&vbLf
tab=tab+"document.write('<param name=""menu"" value=""false"" />'); "&vbLf
tab=tab+"document.write('<param name=wmode value=""opaque"" />'); "&vbLf
tab=tab+"document.write('<param name=""FlashVars"" value=""config='+config+'&bcastr_flie='+files+'&bcastr_link='+links+'&bcastr_title='+texts+'""/>'); "&vbLf
tab=tab+"document.write('<embed src=""images/focus.swf"" wmode=""opaque"" FlashVars=""config='+config+'&bcastr_flie='+files+'&bcastr_link='+links+'&bcastr_title='+texts+'""& menu=""false"" quality=""high"" width=""'+ swf_width +'"" height=""'+ swf_height +'"" type=""application/x-shockwave-flash"" pluginspage=""http://www.macromedia.com/go/getflashplayer"" />'); document.write('</object>');"&vbLf
tab=tab+"</SCRIPT> "&vbLf
GetFlash=tab
end Function 	

Function qq_service_fd()
dim online
sql="select sys_oicq from [Martech_site]"
Set rs1 = conn.execute(sql)
arr_sys_oicq = Split(rs1("sys_oicq"),"$$")
sys_oicq_x = arr_sys_oicq(0)
sys_oicq_Y = arr_sys_oicq(1)
oicq_skin = arr_sys_oicq(2)
oicq_zt = arr_sys_oicq(3)
sys_qq = arr_sys_oicq(4)
qq_zt = arr_sys_oicq(5)
'qq_wz = arr_sys_oicq(6)
'qq_ys = arr_sys_oicq(7)
qq_show = arr_sys_oicq(8)
rs1.close : Set rs1 = Nothing 
If qq_zt=1  Then                  
ontitle="客服在线，点击号码进行交谈"               'QQ在线文字说明
offtitle="客服不在线，点击号码进行留言。"          'QQ离线文字说明
rem 获取全部QQ号码
Dim QQ_num 
Set rss=conn.execute("select * from [Martech_qq_sort] order by q_s_paixu desc")
If not rss.eof Then 
Do While Not rss.eof 
Set rs=conn.execute("select q_num from [Martech_qq] where q_s_id="&rss("q_s_id")&" order by q_paixu desc")
If Not rs.eof Then 
Do While Not rs.eof
QQ_num=QQ_num+CStr(rs("q_num"))+":"
rs.movenext
Loop
End If 
rs.close:Set rs=Nothing 
rss.movenext
Loop
End If 
rss.close
tab=tab+ "<SCRIPT language=javascript>" & vbCrlf
tab=tab+ "function picsize(obj,MaxWidth){" & vbCrlf
tab=tab+ "  img=new Image();" & vbCrlf
tab=tab+ "  img.src=obj.src;" & vbCrlf
tab=tab+ "  if (img.width>MaxWidth)" & vbCrlf
tab=tab+ "  {" & vbCrlf
tab=tab+ "    return MaxWidth;" & vbCrlf
tab=tab+ "  }" & vbCrlf
tab=tab+ "  else" & vbCrlf
tab=tab+ "  {" & vbCrlf
tab=tab+ "    return img.width;" & vbCrlf
tab=tab+ "  }" & vbCrlf
tab=tab+ "}" & vbCrlf
tab=tab+ "function CloseQQ()" & vbCrlf
tab=tab+ "{" & vbCrlf
tab=tab+ "divStayTopleft.style.display=""none"";" & vbCrlf
tab=tab+ "return true; " & vbCrlf
tab=tab+"}" & vbCrlf
'tab=tab+"dim online" & vbCrlf
tab=tab+"var online= new Array();" & vbCrlf
tab=tab+"</SCRIPT>" & vbCrlf
If oicq_zt=1 Then
tab=tab+"<script src=http://webpresence.qq.com/getonline?Type=1&"&QQ_num&"></script>"
End if
tab=tab+"<DIV id=divStay style=""POSITION: absolute""></DIV>" & vbCrlf
tab=tab+"<div id=""divStayTopleft"" style=""POSITION: absolute"">"
tab=tab+"<table border=""0"" width=""100"" cellspacing=""0"" cellpadding=""0"">"&_
                            " <tr><td width=""100""><img src="" images/qq_skin/"&oicq_skin&"_1.gif"" width=""100"" height=""24"" alt=""""></td></tr>"&_
                            " <tr>"&_
	                        "   <td valign=""middle"" background="" images/qq_skin/"&oicq_skin&"_2.gif"">"&_
                            "       <table border=""0"" width=""96%"" cellspacing=""0"" cellpadding=""2"" align=""center"">"
sum_num = Split(QQ_num,":")
Set rs=conn.execute("select * from [Martech_qq_sort] order by q_s_paixu desc")
If rs.eof Then 
Else 
Set rs_1=conn.execute("select q_s_id from [Martech_qq_sort] where q_s_paixu<"&rs("q_s_paixu")&"")
Do While Not rs.eof 
tab=tab+"<tr><td height='20' class='qq_top'>"&Trim(rs("q_s_name"))&"</td></tr>"    
        Set rss=conn.execute("select * from [Martech_qq] where q_s_id="&rs("q_s_id")&" order by q_paixu desc")
        If Not rss.eof Then 
                Do While Not rss.eof 
				If CLng(oicq_zt)=1 Then 
tab=tab+"<script>"&vbcrlf
tab=tab+"if (online["&online_num(rss("q_num"),QQ_num)&"]==0)"&vbcrlf
tab=tab+"document.write('<tr><td>&nbsp;&nbsp;<img src="" images/QQoffline.gif"" border=""0"" align=""middle"" ALT="""&offtitle&""">&nbsp;<a class=""qqb"" target=""blank"" href=""http://wpa.qq.com/msgrd?V=1&amp;Uin="&rss("q_num")&"&amp;Site="&Trim(rs("q_s_name"))&"&amp;Menu=yes"" title="""&offtitle&""">"&Trim(rss("q_name"))&"</a></td></tr>');"&vbcrlf
tab=tab+"else"&vbcrlf
tab=tab+"document.write('<tr><td>&nbsp;&nbsp;<img src="" images/qq_face/"&rss("q_face")&".gif"" border=""0"" align=""absmiddle"">&nbsp;<a class=""qqa"" target=blank href=""http://wpa.qq.com/msgrd?V=1&amp;Uin="&rss("q_num")&"&amp;Site="&Trim(rs("q_s_name"))&"&amp;Menu=yes"" title="""&ontitle&""">"&Trim(rss("q_name"))&"</a></td></tr>');</script>"
				Else 
tab=tab+"<tr><td><a target=""blank"" href=""http://wpa.qq.com/msgrd?V=1&amp;Uin="&rss("q_num")&"&amp;Site="&Trim(rs("q_s_name"))&"&amp;Menu=yes""><img src="" images/qq_face/"&rss("q_face")&".gif"" height=""16"" border=""0"" align=""absmiddle"">"&Trim(rss("q_name"))&"</a></td></tr>"
				End If 
                rss.movenext
                Loop
		End If 
        rss.close:Set rss=Nothing 
rs.movenext
Loop
End If 
rs.close:Set rs=Nothing
tab=tab+"</table></td></tr>"&_
                            " <tr><td width=""100""><img border=""0"" src=""images/qq_skin/"&oicq_skin&"_3.gif""></td></tr>"&_
                            "</table>"&_
                            "</div>"
							
rem 脚本开始
tab=tab+"<script src=""inc/QQ.js""></script>"
End If 
qq_service_fd=tab
End Function 


rem 取一个字符串在一个数组中的位置
Public Function online_num(str,str1)
        If str="" Then 
		      Exit Function 
		End If 
		B=Split(str1,":")
		For I = 0 To UBound(B)
		If InStr(B(i),STR)>0 Then
		 online_num=i
		End If 
		Next 
End Function 

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'单页单条内容调用 by nelson
function IndexAbout(str)
set reg=new regexp
reg.IgnoreCase = False 
reg.Global = True 
reg.Pattern = "{IndexAbout:\{(.+?)\}}"
set aa=reg.execute(str)
FOR each match in aa
bq=match.submatches(0)
'nr=match.submatches(1)
ID=nbq(bq,"ID")
X=nbq(bq,"X")
str=replace(str,match,GetIndexAbout(ID,X))
NEXT
IndexAbout=str
end function

'读取单页单条内容 by nelson
function GetIndexAbout(ID,X)
  set rs = server.createobject("adodb.recordset")
  sql="select Content from Martech_About where ViewFlag and ID="&id
  rs.open sql,conn,1,1
if rs.eof then
'mneirong1=replace(mneirong,"{IndexAbout:Content}","错误参数！")
Content="错误参数！"
else
'mneirong1=replace(mneirong,"{IndexAbout:Content}",left(rs("Content"),X))
Content=left(rs("Content"),X)
end if
xx=xx+Content
GetIndexAbout=xx
 rs.close
 set rs=nothing
end function


''''''单页单条标题调用 by nelson
function IndexAboutName(str)
set reg=new regexp
reg.IgnoreCase = False 
reg.Global = True 
reg.Pattern = "{IndexAboutName:\{(.+?)\}}"
set aa=reg.execute(str)
FOR each match in aa
bq=match.submatches(0)
'nr=match.submatches(1)
ID=nbq(bq,"ID")
X=nbq(bq,"X")
str=replace(str,match,GetIndexAboutName(ID,X))
NEXT
IndexAboutName=str
end function

'''''''读取单页单条标题 by nelson
function GetIndexAboutName(ID,X)
  set rs = server.createobject("adodb.recordset")
  sql="select Name from Martech_About where ViewFlag and ID="&id
  rs.open sql,conn,1,1
if rs.eof then
'mneirong1=replace(mneirong,"{IndexAboutName:Name}","错误参数！")
Name="错误参数！"
else
'mneirong1=replace(mneirong,"{IndexAboutName:Name}",left(rs("Name"),X))
Name=left(rs("Name"),X)
end if
xx=xx+Name
GetIndexAboutName=xx
 rs.close
 set rs=nothing
end function

''''''单页单条描述调用 by nelson
function IndexAboutMiaoshu(str)
set reg=new regexp
reg.IgnoreCase = False 
reg.Global = True 
reg.Pattern = "{IndexAboutMiaoshu:\{(.+?)\}}"
set aa=reg.execute(str)
FOR each match in aa
bq=match.submatches(0)
'nr=match.submatches(1)
ID=nbq(bq,"ID")
X=nbq(bq,"X")
str=replace(str,match,GetIndexAboutMiaoshu(ID,X))
NEXT
IndexAboutMiaoshu=str
end function

'''''''读取单页单条描述 by nelson
function GetIndexAboutMiaoshu(ID,X)
  set rs = server.createobject("adodb.recordset")
  sql="select Miaoshu from Martech_About where ViewFlag and ID="&id
  rs.open sql,conn,1,1
if rs.eof then
'mneirong1=replace(mneirong,"{IndexAboutMiaoshu:Miaoshu}","错误参数！")
Miaoshu="错误参数！"
else
'mneirong1=replace(mneirong,"{IndexAboutMiaoshu:Miaoshu}",left(rs("Miaoshu"),X))
Miaoshu=left(rs("Miaoshu"),X)
end if
xx=xx+Miaoshu
GetIndexAboutMiaoshu=xx
 rs.close
 set rs=nothing
end function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
  %>